<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>融易拍-登录</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm.min.css">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm-extend.min.css">
    <link rel="stylesheet" href="/static/wx/css/reset.css">
    <link rel="stylesheet" href="/static/wx/css/main.css">
    <link rel="stylesheet" href="/static/wx/css/public_main.css">
</head>

<body>
<div class="page-group">
    <div class="page page-current" id="login">
        <!-- 主内容 -->
        <div class="content">
            <div class="logo-box">
                <div class="logo-inner">
                    <div class="logo">
                        <img src="/static/wx/imgs/img/reg.png">
                    </div>
                </div>
            </div>
            <div class="login-form">
                <div class="input-wrapper">
                    <img src="/static/wx/imgs/icon/mobile.png">
                    <div class="after-other"></div>
                    <input class="icon-lable" type="text" placeholder="手机号码" name="phone">
                    <div class="clean-input size-m coffe">
                        <img src="/static/wx/imgs/icon/close.png">
                    </div>
                </div>
                <div class="get-code-box">
                    <div class="input-wrapper" style="width:55%">
                        <img src="/static/wx/imgs/icon/mail.png">
                        <div class="after-other"></div>
                        <input class="icon-lable size-65" type="text" placeholder="请输入验证码" name="code">
                    </div>
                    <div class="get-code size-m" style="width:40%">
                        获取验证码
                    </div>
                </div>
                <div class="my-btn"  style="margin-top: 30px;">
                    <span class="active">登录</span>
                </div>
                <div class="forget-to-regist size-m">
                    <div>
                        <!--<a class="blue">忘记密码？</a>-->
                    </div>
                    <div>
                            <span>
                                还没有账号？<a class="blue external" href="/wx/login/register">注册</a>
                            </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type='text/javascript' src='/static/wx/lib/sui/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/lib/sui/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='/static/wx/lib/sui/sm-extend.min.js' charset='utf-8'></script>
</body>
<script type="text/javascript">
    $(function () {
        //var takse = '';
        var countdown = 60;
        $('.coffe').on('touchend',function(){
            $("input[ name='phone']").val('');
        });
        //短信验证码改变颜色
        function sendmsg() {
            if (countdown == 0) {
                $(".get-code").css({"background-color": "red"});
                $(".get-code").html("获取验证码");
                countdown = 60;
                return false;
            }
            else {
                $(".get-code").css({"background-color": "#C0C0C0", "pointer-events": "none"});
                $(".get-code").html(countdown + "s");
                countdown--;
            }
            setTimeout(function () {
                sendmsg();
            }, 1000);
        }
        //获取验证码
            $(document).on('click','.get-code',function () {
            var pattern = /^1[1345678]\d{9}$/;
            var phone = $("input[ name='phone']").val();
            if (pattern.test(phone) === false) {
                $.alert('请输入正确的手机号');
                return;
            }
            $.ajax({
                type: 'POST',
                url: '/wx/Login/sendSms',
                data: {
                    'phone': phone,
                    'type': 3
                },
                dataType: 'json',
                success: function (Json) {
                    if (Json.code == 200) {
                       var takse = Json.data.code_id;
                        console.log(takse);
                        localStorage.setItem('takse',takse);
                        $.alert('发送成功');
                        sendmsg();
                    } else {
                        $.alert('发送失败');
                    }
                }
            });
        });
        //登录
        $(document).on('click','.my-btn',function () {
            var pattern = /^1[345678]\d{9}$/;
            var phone = $("input[ name='phone']").val();
            var code = $("input[ name='code']").val();
            pattern.test(phone);
            if (pattern.test(phone) === false) {
                $.alert('请输入正确的手机号');
                return;
            }
            if(code.length==0){
                $.alert('请输入验证码');
                return;
            }
            if(localStorage.getItem('takse') ==''){
                $.alert('您的验证码已失效,请重新获取验证码');
                return;
            }
            $.ajax({
                type: 'POST',
                url: '/wx/Login/login',
                data: {
                    'phone': phone,
                    'code': code,
                    'tickets': localStorage.getItem('takse')
                },
                dataType: 'json',
                success: function (Json) {
                    console.log(Json);
                    var data = Json.data;
                    if (Json.code == 200) {
                        if(data.role_id == 4){
                            location.href='/wx/SaleMan/index?type=1';
                        }else{
                            location.href='/wx/Index/index';
                        }
                    } else {
                        $.alert(Json.msg);
                    }
                }
            });
        });
    });


</script>
</html>